<script>
import { getUserInfo } from '@/utils/auth';
import { authReceiveApi, authConfirmApi } from '@/api/me';

export default {
  data() {
    return {
      show: true
    };
  },
  // globalData: {
  //   receiveTimer: null //定时请求是否收到关联申请的定时器
  // },
  onLaunch: async function () {
    console.log('App Launch');
    setTimeout(() => {
      this.show = false;
    }, 3000);

    const token = await getUserInfo('token');
    if (!token) {
      uni.reLaunch({
        url: '/pages-sub/login/login'
      });
    } else {
      // 收到关联申请
      try {
        const result = await authReceiveApi();
        if (result.code === 200 && result.msg) {
          uni.showModal({
            title: '是否同意家长绑定申请',
            content: '申请人',
            cancelText: '暂不授权',
            confirmText: '确认授权',
            confirmColor: '#7DA02F',
            cancelColor: '#D9D9D9',
            success: async (res) => {
              if (res.confirm) {
                const result = await authConfirmApi();
              } else if (res.cancel) {
              }
            }
          });
        }
      } catch (err) {}
    }
  },
  onShow: function () {
    console.log('App Show');
  },
  onHide: function () {
    console.log('App Hide');
    // clearInterval(app.globalData.receiveTimer);
  }
};
</script>

<style lang="scss">
/*每个页面公共css */
@import '@/uni_modules/uview-plus/index.scss';
@import '@/assets/style/common.scss';
@import '@/assets/style/reset.scss';

$u-primary: #6d9319;
$u-info: rgba(216, 216, 216, 1);
.modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
